import instance from '@/utils/axios.js'
import M from 'minimatch'

// 获取导航栏标题
function getChannels() {
  return instance({
    url: '/v1_0/channels',
    method: 'get',
  })
}
export {
  getChannels
}

// 获取文章列表
function getArticleList({
  channel_id,
  timestamp
}) {
  return instance({
    url: '/v1_0/articles',
    method: 'get',
    params: {
      channel_id,
      timestamp,
      with_top: 1
    }
  })
}
export {
  getArticleList
}

// 获取文章详情
function getArticle(id) {
  return instance({
    url: '/v1_0/articles/' + id,
    method: 'get'
  })
}
export {
  getArticle
}

// 关注
function followingUser(id) {
  return instance({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: id
    }
  })
}

export {
  followingUser
}

// 取消关注
function unFollowingUser(id) {
  return instance({
    url: '/v1_0/user/followings/' + id,
    method: 'DELETE',
  })
}

export {
  unFollowingUser
}


//   点赞
function praiseUser(id) {
  return instance({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: id
    }
  })
}

export {
  praiseUser
}

//   取消点赞
function unPraiseUser(id) {
  return instance({
    url: '/v1_0/article/likings/' + id,
    method: 'DELETE',
  })
}

export {
  unPraiseUser
}

//   不喜欢
function disLike(id) {
  return instance({
    url: '/v1_0/article/dislikes',
    method: 'post',
    data: {
      target: id
    }
  })
}
export {
  disLike
}

//   取消不喜欢
function unDisLike(id) {
  return instance({
    url: '/v1_0/article/dislikes/' + id,
    method: 'DELETE',
  })
}

export {
  unDisLike
}

// 搜索推荐词
function getSuggestion(q){
    return instance({
      url: '/v1_0/suggestion',
      method:'get',
      params:{q}
    })
}
export {getSuggestion}

// 搜索结果
function getResult({q,page,per_page}){
  return instance({
    url: '/v1_0/search',
    method: 'get',
    params: {
      q,
      page,
      per_page
    }
  })
}
export {getResult}